import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
    name: 'countDown'
})
export class CountDownPipe implements PipeTransform {

    transform(value: number): string {
        let theTime = value; // 秒
        let theTime1 = 0; // 分
        let theTime2 = 0; // 小时
        if (theTime >= 60) {
            // tslint:disable-next-line:radix
            theTime1 = parseInt(theTime / 60 + '');
            // tslint:disable-next-line:radix
            theTime = parseInt(theTime % 60 + '');
        }
        if (theTime1 > 60) {
            // tslint:disable-next-line:radix
            theTime2 = parseInt(theTime1 / 60 + '');
            // tslint:disable-next-line:radix
            theTime1 = parseInt(theTime1 % 60 + '');
        }

        let result = add0(theTime) + '"';
        if (theTime1 > 0) {
            result = '' + theTime1 + `'` + result;
        } else {
            result = `0'` + result;
        }
        if (theTime2 > 0) {
            result = '' + theTime2 + ':' + result;
        } else {
            result = result;
        }

        return result;
    }
}
function add0(m) {
  if (!m){
    return '00';
  }
  return m < 10 ? '0' + m : m;
}
